package com.bocloud.cmp.driver.providers.jd;

import com.bocloud.cmp.driver.providers.Driver;
import com.bocloud.cmp.driver.providers.ImageDriver;
import com.bocloud.common.model.BsmResult;
import com.jcloud.cap.client.builder.RequestBuilder;

public class JdDriver implements Driver {

	private String accessKey;//
	private String secretKey;//
	private String endpoint;// 服务地址
	private String region;//
	private JdCredential credential;// 统一认证信息

	public String getAccessKey() {
		return accessKey;
	}

	public void setAccessKey(String accessKey) {
		this.accessKey = accessKey;
	}

	public String getSecretKey() {
		return secretKey;
	}

	public void setSecretKey(String secretKey) {
		this.secretKey = secretKey;
	}

	public String getEndpoint() {
		return endpoint;
	}

	public void setEndpoint(String endpoint) {
		this.endpoint = endpoint;
	}

	/**
	 * @return the region
	 */
	public String getRegion() {
		return region;
	}

	/**
	 * @param region
	 *            the region to set
	 */
	public void setRegion(String region) {
		this.region = region;
	}

	/**
	 * @return the credential
	 */
	public JdCredential getCredential() {
		return credential;
	}

	@SuppressWarnings("rawtypes")
	public void init(RequestBuilder builder, String module, String action, String dataCenter) {
		builder.action(action).dataCenter(dataCenter).module(module);
	}

	public JdDriver() {
		super();
	}

	public JdDriver(String accessKey, String secretKey, String endpoint, String region) {
		super();
		this.accessKey = accessKey;
		this.secretKey = secretKey;
		this.endpoint = endpoint;
		this.region = region;
		this.credential = new JdCredential(accessKey, secretKey);
	}

	@Override
	public boolean accessable() {
		ImageDriver driver = new JdImageDriver(this.getAccessKey(), this.getSecretKey(), this.getEndpoint(),
				this.getRegion());
		BsmResult result = driver.list();
		return result.isSuccess();
	}

}
